<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>美食店铺列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/static/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/layuiadmin/style/admin.css" media="all">
    <style>
        #guide_ul li{
            margin-top: 5px;
        }
        .layui-hide{  /*最后的pic为字段的field*/
            height: 100%;
            max-width: 100%;
        }
        .layui-table-cell{
            height:auto !important;
        }
    </style>


</head>
<body>
<div id="aaa"></div>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">美食店铺列表</div>
                <div class="layui-card-body">
                    <div class="layui-form-item layui-form">

                        <!--<div class="layui-inline">-->
                        <!--<div class="layui-inline">-->
                        <!--<div class="layui-btn-group test-table-operate-btn">-->
                        <!--<button class="layui-btn" data-type="addadmin">入住导游</button>-->
                        <!--</div>-->
                        <!--</div>-->
                        <!--</div>-->
                        {if !empty($res)}
                        <div class="layui-inline">
                            <label class="layui-form-label">店铺名字</label>
                            <div class="layui-input-block">
                                <select name="food_store_name" lay-verify="" lay-search id="food_store_name">
                                    <option value="">请选择</option>
                                    {foreach $res as $k=>$v}
                                    <option value="{$v['food_store_name']}">{$v['food_store_name']}</option>
                                    {/foreach}
                                </select>
                            </div>
                            <!--<div class="layui-input-block">-->
                            <!--<input type="text" name="tour_name" id="tour_name" placeholder="请输入" autocomplete="off" class="layui-input">-->
                            <!--</div>-->
                        </div>
                        {/if}

                        <!--<div class="layui-inline">-->
                            <!--<label class="layui-form-label">店铺名字</label>-->
                            <!--<div class="layui-input-block">-->
                                <!--<input type="text" name="food_store_name" id="food_store_name" placeholder="请输入" autocomplete="off" class="layui-input">-->
                            <!--</div>-->
                        <!--</div>-->
                        <div class="layui-inline">
                            <label class="layui-form-label">店铺电话</label>
                            <div class="layui-input-block">
                                <input type="text" name="food_store_tel" id="food_store_tel" placeholder="请输入" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                         <div class="layui-inline">
                            <label class="layui-form-label">入驻时间</label>
                            <div class="layui-input-block">
                                <input type="text" name="create_time" id="test6" placeholder="请输入" autocomplete="off" class="layui-input">
                            </div>
                        </div>   

                        <div class="layui-inline">
                            <div class="layui-btn-group test-table-operate-btn">
                                <button class="layui-btn" data-type="searchUserButton">
                                    <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                                </button>
                            </div>
                        </div>
                    </div>
                    <table class="layui-hide" id="test-table-operate" lay-filter="test-table-operate">
                        <script type="text/html" id="is_use_switch">
                            <input type="checkbox" name="is_login" lay-skin="switch" lay-text="推荐|不推荐" lay-filter="is_use_switch" value="{{ d.is_tuijian }}" data-json="{{ encodeURIComponent(JSON.stringify(d)) }}" {{ d.is_tuijian == 1 ? 'checked' : '' }}>
                        </script>
                         <script type="text/html" id="is_use_switchs">
                            <input type="checkbox" name="is_login" lay-skin="switch" lay-text="置顶|不置顶" lay-filter="is_use_switchs" value="{{ d.is_stick }}" data-json="{{ encodeURIComponent(JSON.stringify(d)) }}" {{ d.is_stick == 1 ? 'checked' : '' }}>
                        </script>
                        <script type="text/html" id="is_display_switch">
                            <input type="checkbox" name="is_display" lay-skin="switch" lay-text="上架|下架" lay-filter="is_display_switch" value="{{ d.is_display }}" data-json="{{ encodeURIComponent(JSON.stringify(d)) }}" {{ d.is_display == 0 ? 'checked' : '' }}>
                        </script>
                    </table>
                    <script type="text/html" id="test-table-operate-barDemo">
                        <a class="layui-btn layui-btn-xs" lay-event="showDetail">详细信息</a>
                        <a class="layui-btn layui-btn-normal layui-btn-xs" id="showImg" lay-event="showImg">店铺相册</a>
                        <!--{{# if(d.is_send==0){ }}-->
                        <!--<a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="sendMerchant">发送商户账号</a>-->
                        <!--{{# } else { }}-->
                        <!--<a class="layui-btn layui-btn-disabled layui-btn-xs" lay-event="">已发送账号</a>-->
                        <!--{{# } }}-->
                        <a class="layui-btn layui-btn-green layui-btn-xs" lay-event="edit">修改</a>
                        <!--<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="yesPass">修改相册</a>-->
                        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="food_del">删除</a>
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>

<div id="contentShow" style="display:none;padding: 30px;">
    <p id="consultation"></p>
</div>
<!--导游信息详情-->
<div id="userDetail" style="display: none;padding:20px;">
    <div class="userDetailCen">
        <ul id="guide_ul">
            <li>
                <p class="p-user">店铺类型：<span id="food_store_tag"></span></p>
            </li>
            <li>
                <p class="p-user">店铺标签：<span id="food_tag"></span></p>
            </li>
            <li>
                <p class="p-user">店铺介绍：<span id="food_store_content"></span></p>
            </li>
            <li>
                <p class="p-user">店铺介绍图片：</p>
                <img src="" id="food_store_content_img" style="width: 160px;height: 100px"/>
            </li>
            <li>
                <p class="p-user">法人身份证：</p>
                <img src="" id="fs_lagal1" style="width: 160px;height: 100px">
                <img src="" id="fs_lagal2" style="width: 160px;height: 100px;margin-left: 15px">
            </li>
            <li>
                <p class="p-user">营业执照：</p>
                <img src="" id="business_license" style="width: 160px;height: 100px"/>
            </li>
            <li>
                <p class="p-user">门头照：</p>
                <img src="" id="m_image" style="width: 160px;height: 100px"/>
            </li>
            <li>
                <p class="p-user">吧台照：</p>
                <img src="" id="b_image" style="width: 160px;height: 100px"/>
            </li>

            <li>
                <p class="p-user">实景图片：</p>
                <div id="live_action">

                </div>

            </li>
        </ul>
    </div>
</div>

<script src="/static/layuiadmin/layui/layui.js"></script>
<script>
   layui.use('laydate', function(){
      var laydate = layui.laydate;  
      //日期范围
      laydate.render({
        elem: '#test6'
        ,range: true
      }); 
    }); 
    layui.config({
        base: '/static/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index','form','table','laydate','set'], function(){
        $ = layui.jquery;
        var table = layui.table
            ,admin = layui.admin
            ,element = layui.element
            ,layer = layui.layer
            ,laydate = layui.laydate
            ,form = layui.form;

        table.render({
            elem: '#test-table-operate'
            ,url: "{:url('Merchant/food')}"
            ,height: 'full-100'
            ,cols: [[
                {field:'food_store_id',width:80,align:'center', title: 'ID'}
                ,{field:'food_store_name',align:'center',title: '店铺名称'}
                ,{field:'food_store_cover',align:'center',title: '店铺封面',style:"height:100px;",templet:function(d){
                        return "<img src=" +d.food_store_cover+ ">"}}
                ,{field:'food_store_tel',align:'center',title: '店铺电话'}
                ,{field:'send_tel',align:'center',title: '接收短信手机号'}
                ,{field:'food_store_address', align:'center', title: '店铺地址',templet:function (d) {
                        return d.city+d.food_store_address
                    }}
                ,{field:'food_people_money', align:'center', title: '人均消费'}
                ,{field:'food_store_time', align:'center', title: '营业时间'}
                ,{field:'examine_time', align:'center', title: '入驻时间'}
               // ,{field:'sort',align:"center",title: '权重(双击可修改)',edit: 'text',style:'cursor: pointer;'}
                ,{field:'is_stick',width:100, align:'center', title: '是否置顶',templet: '#is_use_switchs'}
                ,{field:'is_tuijian',width:100, align:'center', title: '是否推荐',templet: '#is_use_switch'}
                ,{field:'is_display', align:'center', title: '是否上架',templet: '#is_display_switch'}
                ,{align:'center',width:350, title: '操作', toolbar: '#test-table-operate-barDemo'}
            ]]
            ,page:true
            ,limit:10
        });

        form.render(null,'component-form-group');

        laydate.render({
            elem: '#search_time'
        });
        //开关修改管理员状态
        form.on('switch(is_use_switch)', function(obj){
            var loading = layer.load(1, {
                shade: [0.1,'#fff'] //0.1透明度的白色背景
            });
            var json = JSON.parse(decodeURIComponent($(this).data('json')));
            json = table.clearCacheKey(json);

            var is_tuijian = this.checked ? '1' : '0';

            $.ajax({
                url: "{:url('Merchant/isFoodTj')}",
                type: 'post',
                dataType: 'json',
                data: {id:json.food_store_id,is_tuijian:is_tuijian},
                success: function(info){
                    if (info.code === 1) {
                        layer.closeAll()

                    }else{
                        layer.msg(info,{icon:2,time:1000},function(){
                            //layer.close(loading);
                            window.location.reload();
                        });
                    }
                }
            })
        });
   //开关修改管理员状态
        form.on('switch(is_use_switchs)', function(obj){
            var loading = layer.load(1, {
                shade: [0.1,'#fff'] //0.1透明度的白色背景
            });
            var json = JSON.parse(decodeURIComponent($(this).data('json')));
            json = table.clearCacheKey(json);

            var is_stick = this.checked ? '1' : '0';

            $.ajax({
                url: "{:url('Merchant/isFoodStickTj')}",
                type: 'post',
                dataType: 'json',
                data: {id:json.food_store_id,is_stick:is_stick},
                success: function(info){
                    if (info.code === 1) {
                        layer.closeAll()

                    }else{
                        layer.msg(info,{icon:2,time:1000},function(){
                            //layer.close(loading);
                            window.location.reload();
                        });
                    }
                }
            })
        });
        form.on('switch(is_display_switch)', function(obj){
            var loading = layer.load(1, {
                shade: [0.1,'#fff'] //0.1透明度的白色背景
            });
            var json = JSON.parse(decodeURIComponent($(this).data('json')));
            json = table.clearCacheKey(json);

            var is_display = this.checked ? '0' : '1';

            $.ajax({
                url: "{:url('Merchant/isFoodShow')}",
                type: 'post',
                dataType: 'json',
                data: {id:json.food_store_id,is_display:is_display},
                success: function(info){
                    if (info.code === 1) {
                        layer.closeAll()

                    }else{
                        layer.msg(info.msg,{icon:2,time:2000},function(){
                            //layer.close(loading);
                            window.location.reload();
                        });
                    }
                }
            })
        });


        //监听单元格编辑
        table.on('edit(test-table-operate)', function(obj) {
            var loading = layer.load(1, {
                shade: [0.1,'#fff'] //0.1透明度的白色背景
            });
            var reg = /^\d{1,4}$/;
            if (!reg.test(obj.value)) {
                layer.close(loading);
                layer.msg('请输入1-4位数字',{icon:2,time:1500},function(){
                    window.location.reload();
                });

                return false;
            }
            $.ajax({
                url: "{:url('Merchant/editFoodSort')}",
                type: 'post',
                dataType: 'json',
                data: {id:obj.data.food_store_id,sort:obj.value},
                success: function(msg){
                    layer.close(loading);
                    if (msg.code == "0") {
                        layer.close(loading);
                    }else{
                        layer.close(loading);
                        layer.msg(msg.code,{icon:2,time:1500},function(){
                            window.location.reload();
                        });
                    }

                }
            })

        });
        //监听工具条
        table.on('tool(test-table-operate)', function(obj){
            var data = obj.data;
            if(obj.event === 'showDetail'){
                var loading = layer.load(1, {
                    shade: [0.1,'#fff'] //0.1透明度的白色背景
                });
                var food_store_id = data.food_store_id;

                $.ajax({
                    url: "{:url('Merchant/foodInfoDetail')}",
                    type: 'post',
                    dataType: 'json',
                    data: {food_store_id:food_store_id},
                    success: function(data){
                        layer.close(loading);
                        if (data.code === 0) {
                            if(data.data.food_store_tag==""){
                                $('#food_store_tag').html('未设置');
                            }else{
                                $('#food_store_tag').html(data.data.food_store_tag);
                            }
                            if(data.data.food_tag ==""){
                                $('#food_tag').html('未设置');
                            }else{
                                $('#food_tag').html(data.data.food_tag);
                            }
                            if(data.data.food_store_content==''){
                                $('#food_store_content').html('未设置');
                            }else{
                                $('#food_store_content').html(data.data.food_store_content);
                            }
                            if(data.data.guide_card_name==''){
                                $('#guide_card_name').html('未设置');
                            }else{
                                $('#guide_card_name').html(data.data.guide_card_name);
                            }

                            //处理身份证图片
                            var img_src = data.data.fs_lagal;
                            var img_src_arr = img_src.split(',');
                            $('#fs_lagal1').attr('src',img_src_arr[0]);
                            $('#fs_lagal2').attr('src',img_src_arr[1]);
                            //导游照片
                            $('#business_license').attr('src',data.data.business_license);
                            $('#food_store_content_img').attr('src',data.data.food_store_content_img);
                            $('#m_image').attr('src',data.data.m_image);
                            $('#b_image').attr('src',data.data.b_image);
                            var live = data.data.live_action;
                            var live_src = live.split(',');
                            var show = '';

                            $.each(live_src,function (i) {
                                $("#live_action img").remove();
                                show+='<img src="'+live_src[i]+'" style="width: 160px;height: 100px;margin-left: 20px">';
                                $("#live_action").append(show);
                            })

                            var userDetailModal = layer.open({
                                title:'美食店铺详情'
                                ,type: 1
                                ,shadeClose: true
                                ,area:['800px','500px']
                                ,content: $('#userDetail')
                            });
                        }else{
                            layer.msg('获取信息失败',{icon:2,time:1000});
                        }


                    }
                })
            } else if(obj.event === 'showImg'){
                $.ajax({
                    url: "{:url('Merchant/foodImage')}",
                    type: 'post',
                    dataType: 'json',
                    data: {id:data.food_store_id},
                    success: function(msg){
                        if (msg.code == 0) {
                            var arr  = msg.data;
                            let img_src_arr = [];
                            for (var i in arr) {
                                img_src_arr.push(arr[i].img_path)
                            }
                            console.log(img_src_arr);
                            var img_src_data = {};
                            img_src_data.title = '店铺图片';
                            img_src_data.id = data.id;
                            img_src_data.start = 0;
                            img_src_data.data =[];

                            var src = {};

                            for(var i=0;i<img_src_arr.length;i++){
                                src = {};
                                var num = i+1;
                                src.alt = '店铺图片'+ num;
                                src.pid = i;
                                src.src = img_src_arr[i];
                                src.thumb = img_src_arr[i];
                                console.log(src);
                                img_src_data.data.push(src);
                            }
                            layer.photos({
                                photos: img_src_data
                                ,anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机（请注意，3.0之前的版本用shift参数）
                            });
                        }else{
                            layer.msg(msg.message,{time:1000});
                        }
                    }
                });
            } else if(obj.event === 'food_del'){
                layer.confirm('确认删除"' + data.food_store_name + '"吗？', function(index){
                    var loading = layer.load(1, {
                        shade: [0.1,'#fff'] //0.1透明度的白色背景
                    });
                    $.ajax({
                        url: "{:url('Merchant/delFood')}",
                        type: 'post',
                        dataType: 'json',
                        data: {id:data.food_store_id},
                        success: function(msg){
                            layer.close(loading);
                            if (msg.code == 0) {
                                obj.del();
                                layer.close(index);
                            }else{
                                layer.msg(msg.message,{icon:2,time:1000});
                            }
                        }
                    });
                });
            } else if(obj.event === 'sendMerchant'){
                var loading = layer.load(1, {
                    shade: [0.1,'#fff'] //0.1透明度的白色背景
                });
                var guide_id = data.guide_id;
                var guide_tel = data.guide_tel;
                var cardid = data.cardid;
                var rename = data.name;
                $.ajax({
                    url: "{:url('Merchant/sendGuideMerchant')}",
                    type: 'post',
                    dataType: 'json',
                    data: {guide_id:guide_id,guide_tel:guide_tel,cardid:cardid,rename:rename},
                    success: function(data){

                    }
                });
            }else if(obj.event === 'edit'){
                window.location.href="{:url('Merchant/editFood')}?id=" + data.food_store_id;
            }

        });

        var $ = layui.$, active = {
            addadmin: function() {
                window.location.href="{:url('Merchant/guideAdd')}";
            },
            searchUserButton:function(){
                var food_store_name  = $('#food_store_name').val();
                var food_store_tel = $('#food_store_tel').val();
                var food_store_address = $('#food_store_address').val();
                var examine_time = $('#test6').val();
                table.reload('test-table-operate', {
                    where: {
                        food_store_name:food_store_name,
                        food_store_tel: food_store_tel,
                        food_store_address:food_store_address,
                        examine_time:examine_time
                    }
                    ,page: {
                        curr: 1 //重新从第 1 页开始
                    }
                });
                //return false;
            }
        };
        //绑定点击事件
        $('.test-table-operate-btn .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

    });

</script>


</body>
</html>